import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/tool_views/back_nav_btn.dart';
import 'package:flutter_douban/tool_views/my_underline_tabIndicator.dart';
import 'package:flutter_douban/tool_views/nav_title_page.dart';

import 'classroom_category_son_page.dart';

class ClassRoomCategoryPage extends StatefulWidget {
  final String titleStr;
  const ClassRoomCategoryPage({Key? key, required this.titleStr})
      : super(key: key);

  @override
  _ClassRoomCategoryPageState createState() => _ClassRoomCategoryPageState();
}

const List<Tab> _tabs = [
  Tab(text: '         综合         '),
  Tab(text: '         新上线       '),
];

final List<Widget> _tabaContent = [
  ClassRoomCategorySonPage(type: 1,),
  ClassRoomCategorySonPage(type: 2,),
];

class _ClassRoomCategoryPageState extends State<ClassRoomCategoryPage>  with TickerProviderStateMixin{
  late TabController _tabController;
  final PageController pageController = new PageController();
  final ScrollController scrollController = new ScrollController();
  int tabIndex = 0;

  /// 初始化方法 请求数据
  @override
  void initState() {
    super.initState();

    _tabController = TabController(
      length: _tabs.length,
      vsync: this,
      initialIndex: 0, // 默认选中哪一个
    );

    _tabController.addListener(() {
      _tabController.index;
      print('切换了item');
    });
  }

  @override
  void dispose() {
    // 释放对象
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: NavTitlePage(titleStr: widget.titleStr),
          leading: BackNavBtn(),
          backgroundColor: Colors.white,
          bottom: TabBar(
            tabs: _tabs,
            controller: _tabController,
            isScrollable: true,
            labelStyle: TextStyle(fontSize: 15.0,fontWeight: FontWeight.bold),
            unselectedLabelStyle: TextStyle(fontSize: 15.0,),
            indicator: MyUnderlineTabIndicator(
                borderSide: BorderSide(
                    width: 5.0, color: AppColors.yellow)),
            onTap: (index) {
              setState(() {
                tabIndex = index;
              });
            },
          ),
        ),
        body: Container(
          child: TabBarView(
            children: _tabaContent,
            controller: _tabController,
          ),
        ));
  }
}
